package com.redis.demo.controller;

import com.redis.demo.annotation.LockTest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 *
 * @author Admin
 * @date 2024/6/15 14:08
 */
@Component
public class LockTestController {
    public static int num = 0;


    @Scheduled(cron = "0/1 * * * * ?")
    @LockTest(key = "test:1",expired = 3)
    public void test01() {
        LockTestController.num++;
        System.out.println("第 " + num+"次，执行的是第一个");
    }


    @Scheduled(cron = "0/1 * * * * ?")
    @LockTest(key = "test:2",expired = 3)
    public void test02() {
        LockTestController.num++;
        System.out.println("第 " + num+"次，执行的是第二个");
    }



    @Scheduled(cron = "0/1 * * * * ?")
    @LockTest(key = "test:3",expired = 3)
    public void test03() {
        LockTestController.num++;
        System.out.println("第 " + num+"次，执行的是第三个");
    }
}
